package com.test.daily.leetcode.y2022.m05.day0518.v08;

/**
 * @author Tom on 2022/5/18
 */
public class Solution {
    public static class Node{
        public int value;
        public Node next;
        public Node(int value){
            this.value = value;
        }
    }
    public static Node middleOrUpMiddle(Node head){
        if(head == null || head.next == null || head.next.next == null){
            return head;
        }
        // 該鏈表有3個以上數量的節點
        Node slow = head.next;
        Node fast = head.next.next;
        while(fast.next != null && fast.next.next != null){
            slow = slow.next;
            fast = fast.next.next;
        }
        return slow;
    }
}
